package com.spring.xiatian.order.core;

import com.alibaba.druid.pool.DruidDataSource;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 在spring boot 已经有spring-DataSource 从这里也可以自定义dataSource
 * 注意注解的启动先后顺序 ，一般自定义的 mapperscan 启动有可能在
 * dataSource 和 sqlSession之前 可以使用 @AutoConfigureAfter
 * 延迟加载
 * Created by Created by xiaoxia on 2017/10/30 0030 13:37.
 */
//@Configuration
//@MapperScan("com.spring.xiatian.*.dao")
public class DataSourceConfiguration {

    @Value("${jdbc.driver}")
    private String jdbcDriver;

    @Value("${jdbc.url}")
    private String jdbcUrl;

    @Value("${jdbc.username}")
    private String jdbcUserName;

    @Value("${jdbc.password}")
    private String jdbcPassword;

    @Bean("dataSource")
    public DruidDataSource createDataSource() {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName(jdbcDriver);
        dataSource.setUrl(jdbcUrl);
        dataSource.setUsername(jdbcUserName);
        dataSource.setPassword(jdbcPassword);
        return dataSource;
    }

}
